﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
    class Program
    {
              public static void Main()
        {

            // Creates and initializes a multidimensional Array of type String.
            int[] myLengthsArray = new int[2] { 3, 5 };
            int[] myBoundsArray = new int[2] { 1, 1 };
            Array myArray = Array.CreateInstance(typeof(String), myLengthsArray, myBoundsArray);
            for (int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++)
                for (int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++)
                {
                    int[] myIndicesArray = new int[2] { i, j };
                    myArray.SetValue(Convert.ToString(i) + j, myIndicesArray);
                }

            // Displays the lower bounds and the upper bounds of each dimension.
            Console.WriteLine("Bounds:\tLower\tUpper");
            for (int i = 0; i < myArray.Rank; i++)
                Console.WriteLine("{0}:\t{1}\t{2}", i, myArray.GetLowerBound(i), myArray.GetUpperBound(i));

            // Displays the values of the Array.
            Console.WriteLine("The Array contains the following values:");
            PrintValues(myArray);
        }


        public static void PrintValues(Array myArr)
        {
            System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
            int i = 0;
            int cols = myArr.GetLength(myArr.Rank - 1);
            while (myEnumerator.MoveNext())
            {
                if (i < cols)
                {
                    i++;
                }
                else
                {
                    Console.WriteLine();
                    i = 1;
                }
                Console.Write("\t{0}", myEnumerator.Current);
            }
            Console.WriteLine();
        }
    }
    
}
